/*
* @Date: 2020/4/28
* @Author: XueChengwu <xuechengwu@erayt.com>
* @Copyright: 2015-2019 Erayt, Inc.
* @Description: If you have some questions, please contact: xuechengwu@erayt.com.
*/
import Project from './project';
import { message } from 'antd';
import Page from './page';
let project = null;
export default {
  initProject(project) {

  },

  newProject(dirPath) {
    const nameIndex = dirPath.lastIndexOf('\\');
    const name = dirPath.substr(nameIndex + 1, dirPath.length - nameIndex - 1);
    project = new Project(name, dirPath);
  },

  newPage(name, mapPath) {
    if (!project) {
      message.error('请初始化工程');
      return;
    }
    let page = new Page(name, mapPath);
    //TODO: 本地化新建操作
    project.pages.push(page);
    project.pages.sort((a, b) => a.slice(1) > b.slice(1) || -1);
    project.curPath = `${mapPath}/${name}`;
    XUE.win.emit('project-update', 'user');
  },

  newComponent(name, mapPath) {
    if (!project) {
      message.error('请初始化工程');
      return;
    }

  },

  switchPath(path) {
    project.switchPath(path);
    XUE.win.emit('project-update', 'user');
  },

  getProject() {
    return project;
  }
}
